<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改课程')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-grades-edit" th:object="${classGrades}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">班级名称：</label>
                <div class="col-sm-8">
                    <input name="name" th:field="*{name}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control">[[*{remark}]]</textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">班级学生：</label>
                <div class="col-sm-8">
                    <select class="form-control m-b" multiple id="studentIds">
                        <option th:each="student : ${studentList}" th:text="${student.userName}" th:value="${student.userId}"></option>
                    </select>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "system/course";
        $("#form-grades-edit").validate({
            focusCleanup: true
        });

        (function () {
            var studentIds = [[${classGrades}]].studentIds.split(",")
            console.log('studentIds is',studentIds)
            $("#studentIds").val(studentIds)
        })();

        function submitHandler() {
            var studentIds  = $('#studentIds').val()
            console.log('studentIds is',studentIds)
            var data = {
                "id":[[${classGrades}]].id,
                "studentIds":studentIds.join(',')
            }
            console.log('data is',data)
            if ($.validate.form()) {
                $.operate.save(prefix + "/manageStudent",data);
            }
        }
    </script>
</body>
</html>
